<template>
    <div>
        <table class="table table-bordered">
      <tbody>
        <h3>会员添加</h3>
        <tr>
          <td align="right">会员卡号</td>
          <td><input type="text" v-model="Query.Card"/></td>
        </tr>
        <tr>
          <td align="right">会员手机号</td>
          <td><input type="text" v-model="Query.Phone" maxlength="11"/></td>
        </tr>
        <tr>
          <td align="right">会员名称</td>
          <td><input type="text" v-model="Query.MemberName"/></td>
        </tr>
        <tr>
          <td align="right">会员级别</td>
          <td>
            <select v-model="Query.MemberLevelName">
              <option value="">请选择</option>
              <option value="item.LvName" v-for="item in list1">{{ item.LvName }}</option>
            </select>
          </td>
        </tr>
        <tr>
          <td align="right">会员生日</td>
          <td><input type="date" v-model="Query.BirthDay"/></td>
        </tr>
        <tr>
          <td align="right">会员性别</td>
          <td>
            <input type="radio" name="sex" v-model="Query.Sex" value="1"/>男
            <input type="radio" name="sex" v-model="Query.Sex" value="0"/>女
          </td>
        </tr>
        <tr>
          <td align="right">会员积分</td>
          <td>
            <input type="text" v-model="Query.Points"/>
          </td>
        </tr>
        <tr>
          <td align="right">会员余额</td>
          <td>
            <input type="text" v-model="Query.Money"/>
          </td>
        </tr>
        <tr>
          <td align="right">会员爱好</td>
          <td>
            <input type="checkbox" name="likes" v-model="Query.Likes" value="美女"/>美女
            <input type="checkbox" name="likes" v-model="Query.Likes" value="帅哥"/>帅哥
            <input type="checkbox" name="likes" v-model="Query.Likes" value="吃"/>吃
            <input type="checkbox" name="likes" v-model="Query.Likes" value="睡"/>睡
            <input type="checkbox" name="likes" v-model="Query.Likes" value="玩"/>玩
          </td>
        </tr>
        <tr>
          <td align="right">会员简介</td>
          <td>
            <textarea cols="50" rows="5" v-model="Query.Desc"></textarea>
          </td>
        </tr>
        <tr>
          <td align="right"></td>
          <td>
            <input type="button" value="增加" class="btn btn-primary" @click="add" />
          </td>
        </tr>
      </tbody>
    </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
const Route = useRoute();
const Router = useRouter();

let Query:any=reactive({
    "Card": "",
    "Phone": "",
    "MemberName": "",
    "MemberLevelName": "",
    "BirthDay": "",
    "Sex": 1,
    "Points": '',
    "Money": '',
    "Likes": [],
    "Desc": "",
})
let list1: any = ref([]);
onMounted(() => {
    getlist();
})
const getlist = () => {
    axios({
        url: '/api/VIP/GetLvInfo',
        method: 'get',
        params: list1
    })
        .then((res) => {
            console.log(res);
            list1.value = res.data;
        })
        .catch((err) => {
            console.log(err);
        })
}
const add=()=>{
    
    if(Query.Card=="")
    {
        alert("会员卡号不能为空");
        return;
    }
    if(Query.Phone=="")
    {
        alert("手机号不能为空");
        return;
    }
    if(Query.MemberName=="")
    {
        alert("会员名称不能为空");
        return;
    }
    if(Query.MemberLevelName=="")
    {
        alert("会员等级名称不能为空");
        return;
    }
    if(Query.BirthDay=="")
    {
        alert("生日不能为空");
        return;
    }
    if(Query.Sex=="")
    {
        alert("性别不能为空");
        return;
    }
    if(Query.Points=="")
    {
        alert("积分不能为空");
        return;
    }
    if(Query.Money=="")
    {
        alert("余额不能为空");
        return;
    }
    if(Query.Likes=="")
    {
        alert("爱好不能为空");
        return;
    }
    if(Query.Desc=="")
    {
        alert("介绍不能为空");
        return;
    }
    Query.Likes=Query.Likes.toString();
    axios({
        url:'/api/VIP/AddVIP',
        method:'post',
        data:Query
    })
    .then((res) => {
            console.log(res);
            if (res.data == -1) {
                alert("会员等级已存在");
                return;
            }
            else if (res.data > 0) {
                alert("添加成功");
                return;
            }
            else {
                alert("添加失败");
                return;
            }

        })
        .catch((err) => {
            console.log(err);

        })
}
</script>

<style scoped>

</style>